import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';

import '../base/base_app.dart';

/// 创建人： Created by zhaolong
/// 创建时间：Created by  on 2021/9/25.
///
/// gongzhonghao biglead
/// https://study.163.com/instructor/1021410098.htm
/// https://blog.csdn.net/zl18603543572
/// https://www.toutiao.com/c/user/token/MS4wLjABAAAAYMrKikomuQJ4d-cPaeBqtAK2cQY697Pv9xIyyDhtwIM/
///
///
///

//应用入口
void main() {
  ///启动根目录
  runApp(BaseApp(
    homeWidget: Example410(),
  ));
}

///代码清单 4-17
///lib/code/code4/example_410_imageshow_page.dart
///图片浏览器
class Example410 extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _ExampleState();
  }
}

class _ExampleState extends State<Example410> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("分段"),
      ),
      backgroundColor: Colors.white,
      body: Center(child: Container(child: buildSegment(),),),
    );
  }

  ///代码清单 4-11
  ///lib/code4/example_411_segmented_page.dart
  //当前选中的索引
  int _currentIndex = 0;
  buildSegment() {

    return CupertinoSegmentedControl(
      //子标签
      children: const <int, Widget>{
        0: Padding(padding: EdgeInsets.only(left: 12,right: 12),child:Text("全部") ,),
        1: Padding(padding: EdgeInsets.only(left: 12,right: 12),child:Text("收入") ,),
        2: Padding(padding: EdgeInsets.only(left: 12,right: 12),child:Text("支出") ,),
      },
      groupValue: _currentIndex,//当前选中的索引
      onValueChanged: (int index) {//点击回调
        print("当前选中 $index");
        setState(() {
          _currentIndex = index;
        });
      },
      padding: EdgeInsets.all(22),
      selectedColor: Colors.blue, //选中的背景颜色
      unselectedColor: Colors.white, //未选中的背景颜色
      borderColor: Colors.blue,//边框颜色
      pressedColor: Colors.blue.withOpacity(0.4), //按下的颜色
    );
  }
}
